<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>百慧wms仓库</title>
    <link href="../layui/css/layui.css" rel="stylesheet">
</head>
<body>

<div class="layui-fluid">
    <form class="layui-form" style="margin-top: 10px;">
        <input type="hidden" id="menuId" name="menuId">
        <input type="hidden" id="parentId" name="parentId">
        <input type="hidden" id="level" name="level">
        <div class="layui-form-item">
            <label class="layui-form-label">菜单名</label>
            <div class="layui-input-block">
                <input type="text" id="menuName" name="menuName" required  lay-verify="required" placeholder="菜单名" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">是否有效</label>
            <div class="layui-input-block">
                <input type="radio" name="isDelete" value="1" title="有效">
                <input type="radio" name="isDelete" value="0" title="无效" disabled>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">菜单地址</label>
            <div class="layui-input-block">
                <input type="text" id="menuUrl" name="menuUrl"  placeholder="菜单地址,不存在可以为空..." autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">创建时间</label>
            <div class="layui-input-block">
                <input type="text" id="createTime" name="createTime"  placeholder="创建时间"  class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn  layui-btn-normal" lay-submit lay-filter="edit">更新菜单</button>
            </div>
        </div>
    </form>
</div>

<script src="../layui/layui.js"></script>
<script>

    layui.use(["jquery","form","laydate"],function () {
        let $ = layui.jquery;
        let form = layui.form;
        let laydate = layui.laydate;
        let layer = layui.layer;

        laydate.render({
            elem: '#createTime', //指定元素
            type:'datetime',/* 年月日时分秒 */
            theme:'#2F4056 '
        });

        //获取当前页地址
        let url = location.href;
        url=url.substring(url.lastIndexOf("?")+1,url.length);
        if(url.split("=")[1]==1){
            //有效
            $('input[name="isDelete"][value="1"]').attr("checked","checked");
        }else{
            $('input[name="isDelete"][value="0"]').attr("checked","checked");
        }
        //刷新
        form.render("radio");

        /**
         * 提交表单
         */
        form.on("submit(edit)",function (data) {
            console.log(">>>>>>>>",data.field);
            //AJAX
            $.ajax({
                url:"/updateMenu",
                method:"post",
                data:JSON.stringify(data.field),
                contentType:"application/json",
                success:function (d){
                    //关闭弹出层
                    let index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                    parent.layer.close(index); //再执行关闭
                    if(d.code!=0){
                        layer.msg(d.msg);
                    }
                }
            });
            return false;
        });

    });

</script>
</body>
</html>